using Core.Contracts.Interfaces;

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;

    
    public sealed class ChemicalResistance<T> : FeatureBase<object>
    {
        public ChemicalResistance(){}

        public ChemicalResistance(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Chemical resistance"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.Defence; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.ChemicalResistance; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_percent; } }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            // Bonus from bot
            double robotBonus = robot.Modifiers.SumModifiersValues(agent.Extensions, FeatureTypesEnum.Robot, this.FeatureType);

            // Bonus from armor hardeners
            var armorPlatesBonus = robot.Modules.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType, ModuleGroupsEnum.ArmorHardeners);
            double temp = (double)Value * (1 + (robotBonus)) + (armorPlatesBonus);

            var resistperc = temp / (1 + (temp / 100));


            ModifiedValue = IsRounded
                                ? Math.Round(resistperc, 2, MidpointRounding.AwayFromZero)
                                : Math.Round(resistperc, 2);
        }
    }
}